

#include "atomic_op_namespace.h"

#include <sys/atomic.h>

#ifdef __HAVE_ATOMIC64_OPS

uint64_t
atomic_add_64_nv(volatile uint64_t *addr, int64_t val)
{
	uint64_t old, new;

	do {
		old = *addr;
		new = old + val;
	} while (atomic_cas_64(addr, old, new) != old);

	return (new);
}

#undef atomic_add_64_nv
atomic_op_alias(atomic_add_64_nv,_atomic_add_64_nv)
crt_alias(__sync_add_and_fetch_8,_atomic_add_64_nv)

#if defined(_LP64)
#undef atomic_add_long_nv
atomic_op_alias(atomic_add_long_nv,_atomic_add_64_nv)
__strong_alias(_atomic_add_long_nv,_atomic_add_64_nv)

#undef atomic_add_ptr_nv
atomic_op_alias(atomic_add_ptr_nv,_atomic_add_64_nv)
__strong_alias(_atomic_add_ptr_nv,_atomic_add_64_nv)
#endif /* _LP64 */

#endif
